package com.fh.service.impl;

import com.fh.config.UserLoginClient;
import com.fh.config.UserRegistClient;
import com.fh.model.Users;
import com.fh.service.UserRegistService;
import com.fh.utils.ResultState;
import com.fh.vo.ResultVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class UserRegistServiceImpl  implements UserRegistService {
    @Resource
    private UserLoginClient userLoginClient;
   @Resource
   private UserRegistClient userRegistClient;

    @Override
    public ResultVo regist(String username, String password) {
        Users user = userLoginClient.queryUser(username);
        if (user==null){
            Users users=new Users();
            users.setPassword(password);
            users.setUsername(username);
            users.setUserImg("111");
            users.setUserModtime(new Date());
            users.setUserRegtime(new Date());
            int i = userRegistClient.queryUser(users);
            if(i>0){
                return  new ResultVo(ResultState.OK,"注册成功",null);
            }else {
                return  new ResultVo(ResultState.NO,"注册失败",null);
            }
        }else if (user.getUsername()==null){
            return  new ResultVo(501,"电脑太垃圾了",null);
        }else
            {
            return  new ResultVo(501,"账号重复",null);
        }
    }
}
